package club.janna.hello.printer;

import java.lang.reflect.Field;

/**
 * Created by guopanbo on 18/4/20.
 */
public class BeanPrinter {

    public static void print(Object o, String start) {
        if(o == null)
            return;
        Field[] fields = o.getClass().getDeclaredFields();
        if(fields != null)
            for(Field f : fields) {
                f.setAccessible(true);
                try {
                    if (f != null && f.get(o) != null)
                        System.out.printf("%s%s : %s\n", start, f.getName(), f.get(o));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
    }
}
